package gwtmodule1.client.gui.utils;

import com.google.gwt.user.client.ui.Widget;

public class DekoTable extends Table {

	public final static String STYLE_TABLE = "DekoTable";

	public final static String STYLE_HEADER = "DekoTableHeader";

	public final static String STYLE_ITEM = "DekoTableItem";

	private int titleIndex = 0;

	public DekoTable() {
		super();
		setStyleName(STYLE_TABLE);
		setCellPadding(3);
		setCellSpacing(1);
	}

	public void addTitle(String text) {
		setText(0, titleIndex++, text);
	}

	public void addTitle(String text, int colspan) {
		setText(0, titleIndex, text);
		getFlexCellFormatter().setColSpan(0, titleIndex++, colspan);
	}

	public void addTitleWidget(Widget text) {
		setWidget(0, titleIndex++, text);
	}

	public int insertRow(int beforeRow) {
		int i = super.insertRow(beforeRow);
		if (i == 0)
			getRowFormatter().addStyleName(i, STYLE_HEADER);
		else
			getRowFormatter().addStyleName(i, STYLE_ITEM);
		return i;
	}
}
